<?php
require_once 'PHPUnit/Framework.php';
require_once('TVB/PWORKS/util/CommonUtil.class.php');
require_once('TVB/pms/pdes/common/bootstrap.php');

class ProgrammeUpdateActionTest extends PHPUnit_Framework_TestCase
{
	public static $programme_id = 291;

	protected function setUp()
	{
        $this->modified_at = '2009-12-07 15:13:12';
		$this->url = "http://pdes.tvb.com/programme_step2.html?act=edit&step=2&ut=true";
	}

	protected function tearDown()
	{
		$this->url = NULL;
	}

    public function testConcurrentFailed()
    {
		$failed_data = array(
            'id'                => 29,
            'modified_at'       => '2009-12-04 10:00:00',
            'path'              => 'donald_path',
            'cpl_id'            => time(),
            'cpl_company_code'  => 'TVB',
            'tvbcom_cat_id'     => 39,
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if( $err_num > 0 ){
			echo "===========ProgrammeUpdateActionTest concurrent failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        }else{
			echo "===========ProgrammeUpdateActionTest concurrent success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
    }

    public function testTitleFailed()
    {
		$failed_data = array(
            'id'                    => 29,
            'modified_at'           => $this->modified_at,
            'path'                  => 'donald_path',
            'cpl_id'                => time(),
            'cpl_company_code'      => 'TVB',
            'tvbcom_cat_id'         => 39,
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if( $err_num > 0 ){
            echo "\n";
			echo "=====ProgrammeUpdateActionTest title failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        }else{
			echo "=====ProgrammeUpdateActionTest title success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
	}

    public function testEffectiveDateFailed()
    {
		$failed_data = array(
            'id'                    => 29,
            'modified_at'           => $this->modified_at, 
            'path'                  => 'donald_path',
            'cpl_id[0]'              => 'cpl_id1',
            'cpl_id[1]'              => 'cpl_id2',
            'effective_date[0]'      => '2009-12-07 00:00:00',
            'effective_date[1]'      => '2009-12-07 00:00:00',
            'cpl_company_code'      => 'TVB',
            'tvbcom_cat_id'         => 39,
            'title'                 => 'test_title',
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if( $err_num > 0 ){
            echo "\n";
			echo "=====ProgrammeUpdateActionTest effective date failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        }else{
			echo "=====ProgrammeUpdateActionTest effective date success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
	}

    public function testEpisodeTimeOnairFailed()
    {
		$failed_data = array(
            'id'                        => 29,
            'modified_at'               => $this->modified_at, 
            'path'                      => 'donald_path',
            'cpl_id[0]'                 => 'cpl_id1',
            'cpl_id[1]'                 => 'cpl_id2',
            'effective_date[0]'         => '2009-12-07 00:00:00',
            'effective_date[1]'         => '2009-12-08 00:00:00',
            'cpl_company_code'          => 'TVB',
            'tvbcom_cat_id'             => 39,
            'title'                     => 'test_title',
            'first_episode_time_onair'  => '2009-12-07 15:00:00',
            'last_episode_time_onair'   => '2009-12-07 10:00:00',
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if ($err_num > 0) {
            echo "\n";
			echo "=====ProgrammeUpdateActionTest episode time onair failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        } else {
			echo "=====ProgrammeUpdateActionTest episode time onair success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
    }
    
    public function testPublishExpiredTimeFailed()
    {
		$failed_data = array(
            'id'                        => 29,
            'modified_at'               => $this->modified_at, 
            'path'                      => 'donald_path',
            'cpl_id[0]'                 => 'cpl_id1',
            'cpl_id[1]'                 => 'cpl_id2',
            'effective_date[0]'         => '2009-12-07 00:00:00',
            'effective_date[1]'         => '2009-12-08 00:00:00',
            'cpl_company_code'          => 'TVB',
            'tvbcom_cat_id'             => 39,
            'title'                     => 'test_title',
            'first_episode_time_onair'  => '2009-12-07 10:00:00',
            'last_episode_time_onair'   => '2009-12-07 15:00:00',
            'publish_datetime'          => '2009-12-07 01:00:00',
            'expire_datetime'           => '2009-12-01 01:00:00',
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if ($err_num > 0) {
            echo "\n";
			echo "=====ProgrammeUpdateActionTest publish expire datetime failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        } else {
			echo "=====ProgrammeUpdateActionTest publish expire datetime success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
    }

    public function testProductionStartEndDateFailed()
    {
		$failed_data = array(
            'id'                        => 29,
            'modified_at'               => $this->modified_at, 
            'path'                      => 'donald_path',
            'cpl_id[0]'                 => 'cpl_id1',
            'cpl_id[1]'                 => 'cpl_id2',
            'effective_date[0]'         => '2009-12-07 00:00:00',
            'effective_date[1]'         => '2009-12-08 00:00:00',
            'cpl_company_code'          => 'TVB',
            'tvbcom_cat_id'             => 39,
            'title'                     => 'test_title',
            'first_episode_time_onair'  => '2009-12-07 10:00:00',
            'last_episode_time_onair'   => '2009-12-07 15:00:00',
            'publish_datetime'          => '2009-12-01 01:00:00',
            'expire_datetime'           => '2009-12-07 01:00:00',
            'production_start_date'     => '2009-12-07',
            'production_end_date'       => '2009-12-01',
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if ($err_num > 0) {
            echo "\n";
			echo "=====ProgrammeUpdateActionTest production start&&end date failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        } else {
			echo "=====ProgrammeUpdateActionTest production start&&end date success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
    }
    
    public function testPathFailed()
    {
		$failed_data = array(
            'id'                        => 29,
            'modified_at'               => $this->modified_at, 
            'path'                      => 'vanni_path',
            'cpl_id[0]'                 => 'cpl_id1',
            'cpl_id[1]'                 => 'cpl_id2',
            'effective_date[0]'         => '2009-12-07 00:00:00',
            'effective_date[1]'         => '2009-12-08 00:00:00',
            'cpl_company_code'          => 'TVB',
            'tvbcom_cat_id'             => 39,
            'title'                     => 'test_title',
            'first_episode_time_onair'  => '2009-12-07 10:00:00',
            'last_episode_time_onair'   => '2009-12-07 15:00:00',
            'publish_datetime'          => '2009-12-01 01:00:00',
            'expire_datetime'           => '2009-12-07 01:00:00',
            'production_start_date'     => '2009-12-01',
            'production_end_date'       => '2009-12-07',
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if ($err_num > 0) {
            echo "\n";
			echo "=====ProgrammeUpdateActionTest path failed!================" . "\n";
			var_export($real_data);
            echo "\n";
        } else {
			echo "=====ProgrammeUpdateActionTest path success!===============" . "\n";
        }

		$this->assertEquals($err_num , 0); 	
    }

    public function testPremiumProgrammeSuccess()
    {
		$programme = new programme;
		$programme_detail = $programme->get(self::$programme_id);

		$success_data = array(
            'id'                        => self::$programme_id,
            'modified_at'               => $programme_detail->modified_at, 
            'path'                      => $programme_detail->path, 
            'cpl_id[0]'                 => 'cpl_id1',
            'cpl_id[1]'                 => 'cpl_id2',
            'effective_date[0]'         => '2009-12-07 00:00:00',
            'effective_date[1]'         => '2009-12-08 00:00:00',
            'cpl_company_code'          => 'TVB',
            'tvbcom_cat_id[]'           => 39,
            'title'                     => 'ut_test_update_title',
            'first_episode_time_onair'  => '2009-12-07 10:00:00',
            'last_episode_time_onair'   => '2009-12-07 15:00:00',
            'publish_datetime'          => '2009-12-01 01:00:00',
            'expire_datetime'           => '2009-12-07 01:00:00',
            'production_start_date'     => '2009-12-01',
            'production_end_date'       => '2009-12-07',
            'cpl_category_id'           => '',
            'parent_cpl_category'       => '',
            'series_id'                 => '',
            'number_of_episodes'        => '',
            'nominal_duration'          => '',
            'starting_original_episode_no'  => '',
            'production_start_date'     => '',
            'production_end_date'       => '',
            'first_network_codes'       => '',
            'first_time_onair'          => '',
            'first_onair_information'   => '',
            'first_episode_time_onair'  => '',
            'last_episode_time_onair'   => '',
            'publish_datetime'          => '',
            'expire_datetime'           => '',
            'meta_keywords'             => '',
            'meta_description'          => '',
            'minisite_url'              => '',
            'blog_url'                  => '',
            'forum_id'                  => '',
            'average_rating'            => '',
            'highlighted_cast_roles'    => '',
            'casts'                     => '',
            'available_tag_types'       => '',
            'tags'                      => '',
            'auto_publish'              => '',
            'status'                    => 1, 
            'created_at'                => '',
            'created_by'                => '',
            'modified_by'               => '',
            'language_id'               => '',
            'settop_box_name'           => '',
            'description'               => '',
            'description_short'         => '',
            'fact_background'           => '',
            'objective'                 => '',
            'effective_date'            => '',
            'cpl_id'                    => '',
            'cpl_company_code'          => '',
            'category_id'               => '',
            'tag'                       => '',
            'new_tag'                   => '',
            'role_id'                   => '',
            'cast_id'                   => '',
            'name_type'                 => '',
            'name_last'                 => '',
            'name_first'                => '',
            'alphabet'                  => '',
            'title_en'                  => '',
            'param_role_id'             => '',
            'param_cast_id'             => '',
            'param_name_type'           => '',
            'param_last_name'           => '',
            'param_first_name'          => '',
            'param_alphabet'            => '',
            'ut'                        => 1,
            'vid'                       => '',
            'reset'                     => NULL,
            'from'                      => '',
            'act'                       => '',
            'is_folder_update'          => '',

			// premium info
			'premium_title' => 'premium title',
			'premium_items[0]' => 'subscription',
			'subscription_publish_datetime[0]' => date('Y-m-d'),
			'subscription_publish_datetime[1]' => date('H:i'),
			'subscription_expire_datetime[0]' => date('Y-m-d', time()+1000000), 
			'subscription_expire_datetime[1]' => date('H:i'),

			'pt' => 1
		);

		$ret = CommonUtil::curl_test($this->url,$success_data);
		//var_dump($ret);
		$real_data = json_decode($ret, TRUE);
		//var_dump($real_data);

		$err_num = count($real_data);
		if ($err_num == 0) {
            echo "\n";
			echo "=====ProgrammeUpdateActionTest pass!=======";
            echo "\n";
        } else {
            echo "\n";
            echo "=====ProgrammeUpdateActionTest failed!=====" . "\n";
            var_export($real_data);
            echo "\n";
        }

		$this->assertEquals($err_num, 0); 	
	}
}

//$suite = new PHPUnit_Framework_TestSuite('ProgrammeAddActionTest');
//$object = $suite->run();
?>
